#include "CVector.h"
#include <math.h>

CVector::CVector()
{
    fx = fy = 0.0f;
}

CVector::~CVector()
{

}

CVector::CVector(float fxP, float fyP)
{
    fx = fxP;
    fy = fyP;
}

CVector::CVector(int ix, int iy)
{
    fx = (float)ix;
    fy = (float)iy;
}

bool CVector::operator ==(const CVector& cv)
{
    return (fx == cv.fx && fy == cv.fy);
}

bool CVector::operator !=(const CVector& cv)
{
    return ((fx != cv.fx) || (fy != cv.fy));
}

float CVector::Module()
{
    return (float)sqrt((fx * fx) + (fy * fy));
}

void CVector::Normalize()
{
    float fMag = Module();
    fx /= fMag;
    fy /= fMag;
}

CVector CVector::operator-(const CVector& cv)
{
    return CVector(fx - cv.fx, fy - cv.fy);
}

CVector CVector::operator +(const CVector& cv)
{
    return CVector(fx + cv.fx, fy + cv.fy);
}

void CVector::operator+=(const CVector& cv)
{
    fx += cv.fx;
    fy += cv.fy;
}

void CVector::operator -=(const CVector& cv)
{
    fx -= cv.fx;
    fy -= cv.fy;
}

CVector CVector::operator*(const float cfVal)
{
    return CVector(fx*cfVal,fy*cfVal);
}

CVector CVector::operator/(const float cfVal)
{
    return CVector(fx/cfVal,fy/cfVal);
}

void CVector::operator *=(const float cfVal)
{
    fx *= cfVal;
    fy *= cfVal;
}

void CVector::operator /=(const float cfVal)
{
    fx /= cfVal;
    fy /= cfVal;
}

float CVector::DotProduct(const CVector& cv)
{
    return ( (fx*cv.fx) + (fy*cv.fy) );
}

void CVector::Floor()
{
    fx = (float)floor(fx);
    fy = (float)floor(fy);
}

void CVector::Ceil()
{
    fx = (float)ceil(fx);
    fy = (float)ceil(fy);
}
